package com.qf.commerce.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.commerce.common.dto.OrganizationDto;
import com.qf.commerce.common.vo.OrganizationVo;
import com.qf.commerce.entity.Organization;
import com.qf.commerce.mapper.OrganizationMapper;
import com.qf.commerce.service.OrganizationService;
import com.qf.commerce.utils.CommonBeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrganizationServiceImpl implements OrganizationService {
    @Resource
    private OrganizationMapper organizationMapper;

    @Override
    public int insertOrganization(OrganizationDto organizationDto) {
        return organizationMapper.insertOrganization(organizationDto);
    }

    @Override
    public int deleteOrganization(List<Long> ids) {
        return organizationMapper.deleteOrganization(ids);
    }

    @Override
    public int del(int status, Long organizationId) {
        return organizationMapper.del(status,organizationId);
    }

    @Override
    public int updateOrganization(Organization organization, Long organizationId) {
        return organizationMapper.updateOrganization(organization,organizationId);
    }

    @Override
    public Organization selectOrganizationDetail(Long organizationId) {
        return organizationMapper.selectOrganizationDetail(organizationId);
    }

    @Override
    public PageInfo<OrganizationVo> selectOrganization(Integer status, String organizationName, String userName,Integer page, Integer size) {
        return CommonBeanUtils.copyPage(PageHelper.startPage(page,size).doSelectPageInfo(() -> organizationMapper.selectOrganization(status,organizationName,userName)),new PageInfo<OrganizationVo>(),OrganizationVo::new);
    }

    @Override
    public PageInfo<OrganizationVo> selectOrganizationByTime(String startCreateTime, String endCreateTime, Integer page, Integer size) {
        return CommonBeanUtils.copyPage(PageHelper.startPage(page,size).doSelectPageInfo(() -> organizationMapper.selectOrganizationByTime(startCreateTime,endCreateTime)),new PageInfo<OrganizationVo>(),OrganizationVo::new);
    }


}
